#include "RingQueue.hpp"

void *consumer(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    while (true)
    {
        sleep(1);
        int data = 0;
        rq->Pop(&data);
        std::cout << "消费了一个数据: " << data << std::endl;
    }
    return (void*)1;
}

void *productor(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    int data = 1;
    while (true)
    {
        rq->Enqueue(data);
        std::cout << "生产了一个数据: " << data << std::endl;
        data++;
    }
    return (void*)1;
}

int main()
{
    RingQueue<int> *rq = new RingQueue<int>();
    pthread_t c, p;

    pthread_create(&c, nullptr, consumer, (void *)rq);
    pthread_create(&p, nullptr, productor, (void *)rq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);

    delete rq;
    return 0;
}